package com.zwb.service.common.utils;

import org.assertj.core.util.DateUtil;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @author 头发又黑又长
 * @Date 2022/9/8 9:50
 * @email zwb15083976291@163.com
 */
public class ConversionUtil {


    /**
     * data 转换为 LocalDate
     *
     * @param date
     * @return
     */
    public static LocalDate dateToLocalDate(Date date) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }


    /**
     * LocalDateTime 转 Date
     *
     * @param localDateTime
     * @return
     */
    public static Date localDateTimeToDate(LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    /**
     * 字符串转换为date
     * 默认为 yyyy-dd-mm
     *
     * @param parse
     * @return
     */
    public static Date stringToDate(String parse) {
        return DateUtil.parse(parse);
    }

}